package com.znsd.zl.app.user.utils;

import com.alibaba.fastjson.JSONObject;

/**
 * <p>
 *      字符串工具类
 * </p>
 *
 * @ClassName StringUtils
 * @Description TODO
 * @Author jaypdd
 * @Date 2020/9/6 19:47
 * @Version v1.0
 */
public class StringUtils {

	/**
	 * 实体类手机号格式化
	 * @param object    格式化的实体类对象
	 * @return          返回加强后的json对象
	 */
	public static JSONObject phoneEncrypt(Object object) {
		JSONObject jsonObject = (JSONObject) JSONObject.toJSON(object);
		String phone = jsonObject.getString("phone");
		int operatorSize = 8;
		if ( null == phone || phone.length() < operatorSize ) {
			return (JSONObject) JSONObject.toJSON(object);
		}
		StringBuilder str = new StringBuilder(jsonObject.getString("phone"));
		StringBuilder phoneNumber = str.replace(3, 7, "****");
		jsonObject.put("phoneNumber", phoneNumber);
		return jsonObject;
	}
}
